package com.zhidian.edm.controller;

import com.zhidian.edm.param.AddRoleParam;
import com.zhidian.edm.param.UpdateRoleMenuParam;
import com.zhidian.edm.result.ResultResponse;
import com.zhidian.edm.service.ISysRoleService;
import com.zhidian.edm.service.ISysUserService;
import com.zhidian.edm.vo.SysMenuVO;
import com.zhidian.edm.vo.SysRoleVO;
import com.zhidian.edm.vo.SysUserVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sl
 * @since 2025-09-18
 */
@RestController
@RequestMapping("/role")
@Tag(name = "获取角色信息", description = "获取角色信息")
public class SysRoleController {

    @Resource
    private ISysRoleService sysRoleService;

    @GetMapping("/list")
    @Operation(summary = "获取角色列表", description = "获取角色列表")
    public ResultResponse<List<SysRoleVO>> getRoleList(){
        return ResultResponse.success(sysRoleService.getRoleList());
    }

    @GetMapping("/{roleId}")
    @Operation(summary = "根据角色id获取详情", description = "根据角色id获取详情")
    public ResultResponse<SysRoleVO> getRoleDetailById(@PathVariable("roleId") Long roleId){
        return ResultResponse.success(sysRoleService.getRoleDetailById(roleId));
    }

    @DeleteMapping("/{roleId}")
    @Operation(summary = "通过角色id删除角色", description = "通过角色id删除角色")
    public ResultResponse deleteRoleById(@PathVariable("roleId") Long roleId){
        sysRoleService.deleteRoleById(roleId);
        return ResultResponse.success();
    }

    @PutMapping("/update")
    @Operation(summary = "更新角色授权信息", description = "更新角色授权信息")
    public ResultResponse updateRoleAndMenuAuth(@RequestBody UpdateRoleMenuParam  param){
        sysRoleService.updateRoleAndMenuAuth(param);
        return ResultResponse.success();
    }

    @PostMapping("/add")
    @Operation(summary = "添加角色", description = "添加角色")
    public ResultResponse addRole(@RequestBody AddRoleParam param){
        sysRoleService.addRole(param);
        return ResultResponse.success();
    }


}
